<%--
  Created by IntelliJ IDEA.
  User: 14533
  Date: 2021/10/28
  Time: 15:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="css/amazeui.min.css">
    <link rel="stylesheet" href="css/admin.css">
</head>
<body>
<div class="admin-content-body" style="">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">部门管理</strong><small></small></div>
    </div>
    <hr>
    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <button type="button" class="am-btn am-btn-default btnAdd">
                        <span class="am-icon-plus"></span> 新增
                    </button>
                    <button type="button" style="margin-left: 20px;" class="am-btn am-btn-default" onclick="sendReq(0)">
                        <span class="am-icon-archive"></span> 有效部门
                    </button>
                    <button type="button" style="margin-left: 20px;" class="am-btn am-btn-default" onclick="sendReq(1)">
                        <span class="am-icon-archive"></span> 已撤销部门
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="am-g" style="margin-top: -30px;">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-check">
                            <input id="chkAll" type="checkbox">
                        </th>
                        <th class="table-id">
                            ID
                        </th>
                        <th class="table-title">
                            部门名称
                        </th>
                        <th class="table-title">
                            部门职责
                        </th>
                        <th class="table-title">
                            创建时间
                        </th>
                        <th class="table-title">
                            部门状态
                        </th>
                        <th class="table-set">
                            操作
                        </th>
                    </tr>
                    </thead>
                    <tbody id="tUser">
                    <c:forEach items="${departs}" var="depart">
                        <tr>
                            <td><input name="chks" value="27" type="checkbox"></td>
                            <td>${depart.did}</td>
                            <td>${depart.dname}</td>
                            <td>${depart.duty}</td>
                            <td><fmt:formatDate value="${depart.credate}" pattern="yyyy年MM月dd日"/></td>
                            <td>${depart.dstatus==0?'在使用':'已撤销'}</td>
                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <c:if test="${depart.dstatus==0}">
                                            <button type="button" onclick="findByDid(${depart.did})" id="depart_27" class="am-btn am-btn-default am-btn-xs am-text-secondary btnedit">
                                                <span class="am-icon-pencil-square-o"></span> 编辑
                                            </button>
                                            <button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger amt-hide-sm-only" onclick="updateDstatus(${depart.did}, 1)">
                                                <span class="am-icon-trash-o"></span> 删除
                                            </button>
                                        </c:if>
                                        <c:if test="${depart.dstatus==1}">
                                            <button type="button" onclick="updateDstatus(${depart.did}, 0)" id="depart_27" class="am-btn am-btn-default am-btn-xs am-text-secondary btnedit">
                                                <span class="am-icon-pencil-square-o"></span> 恢复
                                            </button>
                                        </c:if>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </c:forEach>

                    </tbody>
                </table>
            </form>
        </div>
    </div>
</div>
<script src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="myplugs/js/plugs.js"></script>
<script>
    $(function() {
        $("#chkAll").chkAll({});
        // $(".btnedit").click(function() {
        //     $.jq_Panel({
        //         title: "编辑部门",
        //         iframeWidth: 500,
        //         iframeHeight: 300,
        //         url: "findDepart"
        //     });
        //     //window.location.href = "editDepart?did=" + did;
        // });
        $(".btnAdd").click(function() {

            $.jq_Panel({
                title: "添加部门",
                iframeWidth: 500,
                iframeHeight: 300,
                url: "addDepart.html"
            });
        });
    });

    function sendReq(dstatus) {
        window.location.href = "findAllDepart?dstatus=" + dstatus;
    }

    function findByDid(did) {
        $.jq_Panel({
            title: "编辑部门",
            iframeWidth: 500,
            iframeHeight: 300,
            url: "findByDid?did=" + did
        });
    }

    function updateDstatus(did, dstatus) {
        window.location.href = "updateDstatus?did=" + did + "&dstatus=" + dstatus;
    }
</script>
</body>
</html>
